package com.qf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 29125
 * @version V1.0
 * @Project java2203
 * @Package com.qf.controller
 * @Description:消费者登录的验证码功能实现
 * @Date 2022/5/23 11:38
 */
@WebServlet("/code")
public class CodeController extends BaseServlet {
    //创建验证码
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //创建验证码工具类  由页面知道需要参数:宽度，高度，字符个数
        ValidateCode validateCode=new ValidateCode(100,30,4,10);
        //验证码工具类获取验证码
        String code = validateCode.getCode();
        //验证码存入session会话中
        request.getSession().setAttribute("code",code);
        //将验证码图片通过流回写到页面展示、
        validateCode.write(response.getOutputStream());
    }
}
